package com.medicine.mapper;

import com.medicine.entity.GroupMedicine;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GroupMedicineMapper {
    /**
     * 根据药品id查询对应的药组id
     *
     * @param medicineIds
     * @return
     */
    //select group_id from group_medicine where medicine_id in (1,2,3,4)
    List<Long> getGroupIdsByMedicineIds(List<Long> medicineIds);

    /**
     * 批量保存药组和药品关联关系
     * @param groupMedicines
     */
    void insertBatch(List<GroupMedicine> groupMedicines);

    /**
     * 根据套餐id删除套餐和菜品的关联关系
     * @param setmealId
     */
    @Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
    void deleteByGroupId(Long setmealId);

    /**
     * 根据药组id查询药组和药品的关联关系
     * @param groupId
     * @return
     */
    @Select("select * from group_medicine where group_id = #{groupId}")
    List<GroupMedicine> getByGroupId(Long groupId);

    /**
     * 根据药品id查询药品对应药组关系
     * @param id
     * @return
     */
    @Select("select * from group_medicine where medicine_id = #{id}")
    GroupMedicine getGroupMedicineByMedicineId(Long id);
}

